package com.swufe.myapplication;
import android.content.Context;
import android.view.Gravity;
import android.widget.FrameLayout;
import android.widget.TextView;

public class Card  extends FrameLayout {
    private int num;
    private TextView label;
    static String[] colors = {"0x00000000", "0xffeee4da", "0xffede0c8", "0xfff2b179", "0xfff59563", "0xfff67c5f",
            "0xfff65e3b", "0xffedcf72", "0xffffff00", "0xffccff00", "0xff99ff00"};
/*2022/5/28*/
    public Card(Context context) {
        super(context);
        label = new TextView(getContext());
        label.setTextSize(25);
        label.setGravity(Gravity.CENTER);
        label.setBackgroundColor(0x33ffffff);

        LayoutParams lp = new LayoutParams(-1, -1);//该类用来初始化layout控件textView里的高和宽属性
        lp.setMargins(5, 5, 5, 5);
        addView(label, lp);
        setNum(0);
    }

    public int getNum() {
        return num;
    }

    public void setNum(int num) {
        this.num = num;
        if (num <= 0) {
            label.setText("");
        } else {
            label.setText(num + "");
        }
        switch (num){
            case 0:
                label.setBackgroundColor(0x00000000);
                break;
            case 2:
                label.setBackgroundColor(0xffeee4da);
                break;
            case 4:
                label.setBackgroundColor(0xffede0c8);
                break;
            case 8:
                label.setBackgroundColor(0xfff2b179);
                break;
            case 16:
                label.setBackgroundColor(0xfff59563);
                break;
            case 32:
                label.setBackgroundColor(0xfff67c5f);
                break;
            case 64:
                label.setBackgroundColor(0xfff65e3b);
                break;
            case 128:
                label.setBackgroundColor(0xffedcf72);
                break;
            case 256:
                label.setBackgroundColor(0xff99ff00);
            case 512:
                label.setBackgroundColor(0xffffff00);
                break;
            case 1024:
                label.setBackgroundColor(0xffccff00);
                break;
            case 2048:
                label.setBackgroundColor(0xff99ff00);
                break;
        }
    }
    //判读两张卡片的值是否相等
            public boolean equals (Card c){
                return getNum() == c.getNum();
            }
}
